Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
Sequelize "object" does not have increment function

I am using generate sequelize tables from Django generated models with sequelize-auto in my project. so far so good. I wrote the code to update the rank if I see a url again.

const findLink = async (link) =>
  Link.findOne({
    where: {
      url: link,
    },
    raw: true,
  });
// eslint-disable-next-line no-use-before-define
const insertEvent = async (link, tweetText) => {
  // Sync Database table before reading
  await sequelize.sync();
  findLink(link).then((url) => {
    if (url) {
      url.increment("rank", {by: 1}).then(()=>{
      Event.create({
        url_id: url.id,
        tweet_text: tweetText,
        created_at: new Date(),
        updated_at: new Date(),
      })
    });

    } else {
      Link.create({
        url: link,
        rank: 0,
        created_at: new Date(),
        updated_at: new Date(),
      }).then((newLink) => {
        Event.create({
          url_id: newLink.id,
          tweet_text: tweetText,
          created_at: new Date(),
          updated_at: new Date(),
        });
      });
    }
  });
};

But the problem is that when It execute url.increment("rank", {by: 1}) it says that url does not have increment function.

But according to documentation it is clearly stated here. Please let me know if I am doing something wrong? I have searched the internet but I could not find any thing relative. I can update the value with duplicate look up but I am looking for a way If I could update the already found object instead of searching it again.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are using raw queries

const findLink = async (link) =>
  Link.findOne({
    where: {
      url: link,
    },
    raw: true,
  });

It doesn't return an instance of the Model

See https://sequelize.org/master/manual/raw-queries.html

Edit:

By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).

A second option is the model. If you pass a model the returned data will be instances of that model.

// Callee is the model definition. This allows you to easily map a query to a predefined model
const projects = await sequelize.query('SELECT * FROM projects', {
  model: Projects,
  mapToModel: true // pass true here if you have any mapped fields
});
// Each element of `projects` is now an instance of Project

So the mapToModel option might also work

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda